package com.naiterui.ehp.bs.doctor.controller.inner;

import java.io.IOException;

import com.naiterui.ehp.bp.constants.SwaggerTag;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bp.support.exception.PublicService;
import com.naiterui.ehp.bp.support.exception.ResponseVO;
import com.naiterui.ehp.bs.doctor.exception.ExceptionCodes;
import com.naiterui.ehp.bs.doctor.service.security.ISecurityService;


@Controller
@RequestMapping("ad/inner/token")
@Api(tags = {SwaggerTag.DOCTOR + SwaggerTag.INNER_API + SwaggerTag.OTHER})
public class AdInnerTokenController {

    @Autowired
    private ISecurityService securityService;

    @ResponseBody
    @RequestMapping("check")
    public ResponseVO<Boolean> checkToken(Long doctorId, String token) throws BusinessException, IOException {

        if (null == doctorId || StringUtils.isBlank(token)) {
            throw new BusinessException(ExceptionCodes.PARAM_ERROR);
        }

        boolean result = securityService.saveCheckToken(doctorId, token);

        return PublicService.returnResponseVO(ExceptionCodes.SUCCESS, result);
    }
}